package com.lib76.DBInfo.service;

import java.sql.SQLClientInfoException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lib76.DBInfo.dao.MysqlInfoDao;

/**
 * 数据库信息访问工厂
 * @author 张浩
 * @version 0.0.1
 */
public class DatabaseInfoDaoFactory {

	static Logger logger = LoggerFactory.getLogger(DatabaseInfoDaoFactory.class);
	
	/**
	 * 创建数据库信息访问对象
	 * @param dbType
	 * @param ip
	 * @param port
	 * @param userName
	 * @param userPwd
	 * @return
	 */
	public static IDatabaseInfoDao createDatabaseInfoDao(String dbType,String ip,Integer port,String userName,String userPwd){
		return createDatabaseInfoDao(DatabaseTypeEnum.valueOf(dbType),ip,port,userName,userPwd);
	}
	
	/**
	 * 创建数据库信息访问对象
	 * @param dbType
	 * @param ip
	 * @param port
	 * @param userName
	 * @param userPwd
	 * @return
	 */
	public static IDatabaseInfoDao createDatabaseInfoDao(DatabaseTypeEnum dbType,String ip,Integer port,String userName,String userPwd){
		try {
			if(DatabaseTypeEnum.MYSQL.equals(dbType)){
				return new MysqlInfoDao(ip,port,userName,userPwd);
			}
		} catch (SQLClientInfoException e) {
			logger.error("创建数据库信息访问对象错误", e);
		}
		return null;
	}
}
